package com.financing.wap.web.controller.api;


import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.wap.common.ResultMap;
import com.financing.wap.common.ResultMap.STATUS;
import com.financing.wap.dto.ActivitesMollionsWealthDTO;
import com.financing.wap.dto.ProductDetailPageDTO;
import com.financing.wap.dto.ProjectCompanyDTO;
import com.financing.wap.service.IActivitieGiftService;
import com.financing.wap.service.IActivitiesMollionsWealthService;
import com.financing.wap.service.ISystemService;
import com.financing.wap.web.controller.BaseController;

/**
 * 
 * @ClassName: ActivitiesMollionsWealthController
 * @Description: 查询百万财富产品列表 
 * @author  qiye
 * @date 2015年1月18日 下午5:35:58
 *
 */
@Controller("apiActivitiesMollionsWealthController")
@RequestMapping("/api/mollionsWealth")
public class ActivitiesMollionsWealthController extends BaseController {

	@Autowired
	private IActivitiesMollionsWealthService activitesMollionsWealthService;
	
	@Autowired
	private IActivitieGiftService activitieGiftServiceImpl;
	
	@Autowired
	private ISystemService systemService;
	
	@RequestMapping("mollionsWealthProductList")
	@ResponseBody
	public ResultMap mollionsWealthProductList(HttpServletRequest request, HttpServletResponse response,ActivitesMollionsWealthDTO dto){
		ResultMap result = new ResultMap();
		log.info("query mollionsWealthProductList!");
		 try {
			
			 List<Map<String,Object>> list = activitesMollionsWealthService.queryActivitiesMollionsWealthList(dto);
			 for (int i = 0; i < list.size(); i++) {
				 Map<String,Object> bean = list.get(i);
				 ProductDetailPageDTO productDetailPageDTO = (ProductDetailPageDTO) bean.get("ProductDetail");
				 productDetailPageDTO.setSummary(null);
				 productDetailPageDTO.setRiskRankComtent(null);
				 ProjectCompanyDTO projectCompanyDTO = (ProjectCompanyDTO) bean.get("ProjectCompany");
				 if(projectCompanyDTO !=null){
				 projectCompanyDTO.setcIntroduction(null);
				 }
			}
			result.setAttribute("list", list);
			result.setStatus(STATUS.SUCCESS);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
		} catch (Exception e) {
			result.setStatus(STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
			log.error("query mollionsWealthProductList error!",e);
		}
		return result;
	}
	
	@RequestMapping("mollionsWealthCount")
	@ResponseBody
	public ResultMap mollionsWealthCount(){
		ResultMap result = new ResultMap();
		log.info("mollionsWealthCount!");
		 try {
			 BigDecimal count = activitieGiftServiceImpl.mollionsWealthCount();
			 if(count == null){
				 count = new BigDecimal(0.00);
			 }
			 count =  count.add(systemService.getMollionWealthCount());
			 result.setAttribute("mollionsWealthNow", count);
			 result.setAttribute("mollioinsWealthLeft", new BigDecimal(1000000).subtract(count));
			result.setStatus(STATUS.SUCCESS);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
		} catch (Exception e) {
			result.setStatus(STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
			log.error("query mollionsWealthProductList error!",e);
		}
		return result;
	}
	
}
